package com.my.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.my.admin.entity.Menu;
import com.my.admin.entity.Role;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author my
 */
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select role_id from user_role where is_delete = false AND user_id = #{userId}")
    List<Long> roleListByUserId(long userId);

    @Select("select m.id, m.name, m.parent_id, m.deep, (r.id is not null) as checked from menu m left join role_menu r on m.id = r.menu_id and r.role_id = #{roleId} and r.is_delete = false where m.is_delete = false")
    List<Menu> menuListByRoleId(long roleId);

}
